/*
 * 
 * Created on Jul 25, 2005
 */
package remato.client.view.editor.usertypes;

import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.StructuredViewer;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;

import remato.client.controller.RequirementPlugin;
import remato.client.model.AbstractPropertySpesification;
import remato.client.model.PropertySpecification;
import remato.client.view.facade.IModelTableEditor;
import remato.domain.common.Category;
import remato.domain.common.Requirement;

/**
 * 
 * @author Petter L. H. Eide
 * @version $Id: DeleteUserTypesTableRowAction.java,v 1.1 2006-01-23 19:58:37 petterei Exp $
 * 
 * Changelog:
 * 
 * $Log: DeleteUserTypesTableRowAction.java,v $
 * Revision 1.1  2006-01-23 19:58:37  petterei
 * initial commit for client, fitting the alternative session implementation
 *
 * Revision 1.1  2005-12-03 14:38:48  petterei
 * *** empty log message ***
 *
 * Revision 1.1  2005/11/16 16:43:28  petterei
 * mye testing...
 *
 * Revision 1.2  2005/08/25 09:46:30  peide3
 * added batch update + bugfixes
 *
 * Revision 1.1  2005/08/23 06:38:13  peide3
 * *** empty log message ***
 *
 * Revision 1.1  2005/07/31 22:55:10  petterei
 * initial commit
 *
 *
 */
public class DeleteUserTypesTableRowAction extends UserTypesTableAction {

    public DeleteUserTypesTableRowAction(StructuredViewer viewer) {
        super("Delete " + PropertySpecification.class.getSimpleName() +"(s)");
        init(viewer);
    }

    private void init(StructuredViewer viewer) {
        setViewer(viewer);
        setToolTipText("Delete selected "+ PropertySpecification.class.getSimpleName() +"(s), for " + Requirement.class.getSimpleName() + "s of this " + Category.class.getSimpleName());
        setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
                getImageDescriptor(ISharedImages.IMG_TOOL_DELETE)); //TODO: change image
    }

    @Override
    public void run() {
        StructuredSelection selection = (StructuredSelection)getViewer().getSelection();
        if ( MessageDialog.openConfirm(RequirementPlugin.getInstance().getActiveShell(),"Really delete?", "Do you want to delete the " + selection.size() + " selected " + PropertySpecification.class.getSimpleName()) ) {
            for (Object object : selection.toList()) {
                if (object instanceof AbstractPropertySpesification) {
                	AbstractPropertySpesification spec = (AbstractPropertySpesification) object;
                    ((IModelTableEditor<AbstractPropertySpesification>)getViewer().getContentProvider()).removeElement(spec);
                }
            }
        }
        super.run();
    }

    
}
